home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-10-11 | 6.0 KB | 220 lines | [TEXT/CWIE] |
- // CTextBoxDialog.cp
- // Copyright © 1995 by Michael F. Kamprath, All rights reserved.
- //
- // Contact information:
- // mailto:kamprat@leonardo.net
- // http://www.leonardo.net/kamprath
- //
- // License:
- // This code may be freely used in free and shareware products. Commercial product
- // users must supply me with a free, fully licensed copy of the product this code is
- // used in. In either case, users should notify me of their use of this code.
- //
- // This code may be freely distributed in it's non-modified form. It's original archive
- // should be kept intact.
- //
- // Version History:
- // v1.0.0 - Inititial release.
- //
-
- #include <Dialogs.h>
- #include <Controls.h>
- #include "CTextBoxDialog.h"
-
- pascal void TextBoxItem( WindowPtr theWindow, short itemNo);
- pascal void TextScrollProc(ControlHandle theControl, short partCode);
-
- CTextBoxDialog::CTextBoxDialog( short dlogResID, short textResID )
- : CModalDialog( dlogResID, CTextBoxDialog::kOK, CTextBoxDialog::kOK )
- {
- short itemType, height;
- Handle itemHandle, textH, styleH;
- Rect itemRect, textRect;
-
- this->textBoxUPP = NewUserItemProc( TextBoxItem );
- this->GetItemInfo(kTextBox, &itemType, &itemHandle, &textRect );
- this->SetItemInfo(kTextBox, kUserDialogItem, (Handle)this->textBoxUPP, &textRect );
- this->SetDialogPort();
- this->aboutTEH = ::TEStyleNew(&textRect, &textRect);
- textH = ::Get1Resource('TEXT',textResID);
- styleH = ::Get1Resource('styl',textResID);
- HLock( textH );
- ::TEStyleInsert( *textH, GetHandleSize(textH), (StScrpHandle)styleH, this->aboutTEH);
- HUnlock( textH );
- ReleaseResource( textH );
- ReleaseResource( styleH );
- ::TECalText(this->aboutTEH);
- ::TEAutoView(true, this->aboutTEH);
- ::TEActivate(this->aboutTEH);
-
- height = ::TEGetHeight((*this->aboutTEH)->nLines, 0, this->aboutTEH);
- this->GetItemInfo(kScrollBar, &itemType, &itemHandle, &itemRect );
- ::SetControlMaximum((ControlHandle)itemHandle, height - (textRect.bottom - textRect.top) );
-
- this->scrollProcUPP = NewControlActionProc(TextScrollProc);
- }
-
- CTextBoxDialog::~CTextBoxDialog()
- {
- DisposeRoutineDescriptor((UniversalProcPtr)this->textBoxUPP);
- DisposeRoutineDescriptor((UniversalProcPtr)this->scrollProcUPP);
- ::TEDispose(this->aboutTEH);
- }
-
- void
- CTextBoxDialog::DisplayTextBoxDialog( void )
- {
- short itemHit;
- Boolean done = false;
-
- this->Show();
-
- while (!done)
- {
- itemHit = this->DoOneModalLoop();
-
- switch (itemHit)
- {
- case kOK:
- done = true;
- break;
- case kScrollBar:
- break;
-
- }
- }
-
- this->Hide();
- }
-
- Boolean
- CTextBoxDialog::KeyDownFilter( DialogPtr theDlg, EventRecord *theEvent, short *itemHit)
- {
- Boolean returnCode = false;
- char key = theEvent->message&charCodeMask;
-
- if (theEvent->modifiers&cmdKey)
- {
- if ((key == 'c')||(key == 'C'))
- {
- ::TECopy(this->aboutTEH);
- returnCode = true;
- }
- else if ((key == 'a')||(key == 'A'))
- {
- ::TESetSelect(0, 32767, this->aboutTEH);
- returnCode = true;
- }
- }
-
- if (!returnCode)
- returnCode = this->CModalDialog::KeyDownFilter( theDlg, theEvent, itemHit);
-
- return returnCode;
- }
-
- Boolean
- CTextBoxDialog::MouseDownFilter( DialogPtr theDlg,
- EventRecord* theEvent,
- short* itemHit )
- {
- ControlHandle theControl;
- GrafPtr savePort;
- short foundItem, thePart;
- short itemType, newVal;
- Handle itemHandle;
- Rect itemRect;
- Point thePt;
- Boolean returnCode = false;
-
- ::GetPort( &savePort );
- ::SetPort( theDlg );
- thePt = theEvent->where;
- ::GlobalToLocal( &thePt );
-
- this->GetItemInfo( kTextBox, &itemType, &itemHandle, &itemRect );
- if (::PtInRect(thePt, &itemRect))
- {
- ::TEClick(thePt, theEvent->modifiers&shiftKey ? true : false, this->aboutTEH);
- this->GetItemInfo( kScrollBar, &itemType, &itemHandle, &itemRect );
- newVal = (*this->aboutTEH)->viewRect.top - (*this->aboutTEH)->destRect.top;
- ::SetControlValue( (ControlHandle)itemHandle, newVal );
- *itemHit = kTextBox;
- returnCode = true;
- }
- else
- {
- this->GetItemInfo( kScrollBar, &itemType, &itemHandle, &itemRect );
- foundItem = ::FindControl(thePt, theDlg, &theControl);
- if (theControl == (ControlHandle)itemHandle)
- {
- if (foundItem == kControlIndicatorPart)
- {
- this->lastScrollValue = ::GetControlValue( theControl );
- thePart = ::TrackControl(theControl, thePt, nil);
- newVal = ::GetControlValue( theControl );
- ::TEPinScroll(0, this->lastScrollValue - newVal, this->aboutTEH);
- }
- else
- thePart = ::TrackControl(theControl, thePt, this->scrollProcUPP);
- if (thePart)
- *itemHit = kScrollBar;
-
- returnCode = true;
- }
- }
-
- ::SetPort( savePort );
-
- if (!returnCode)
- returnCode = this->CModalDialog::MouseDownFilter( theDlg, theEvent, itemHit);
-
- return returnCode;
- }
-
- pascal void TextBoxItem( WindowPtr theWindow, short /* itemNo */)
- {
- short itemType;
- Handle itemHandle;
- Rect itemRect;
- CTextBoxDialog *theThis = (CTextBoxDialog *)GetWRefCon( theWindow );
-
- theThis->GetItemInfo( CTextBoxDialog::kTextBox, &itemType, &itemHandle, &itemRect );
-
- ::TEUpdate(&itemRect, theThis->aboutTEH);
-
- MoveTo( itemRect.right, itemRect.top - 1);
- LineTo( itemRect.left - 2, itemRect.top - 1);
- LineTo( itemRect.left - 2, itemRect.bottom + 1);
- LineTo( itemRect.right, itemRect.bottom + 1);
- }
-
- pascal void TextScrollProc(ControlHandle theControl, short partCode)
- {
- short newVal;
- CTextBoxDialog *theThis;
-
- HLock( (Handle)theControl );
- theThis = (CTextBoxDialog *)GetWRefCon( (*theControl)->contrlOwner );
- HUnlock( (Handle)theControl );
- theThis->lastScrollValue = GetControlValue( theControl );
- switch (partCode)
- {
- case kControlUpButtonPart:
- SetControlValue( theControl, GetControlValue( theControl ) - 10 );
- break;
- case kControlDownButtonPart:
- SetControlValue( theControl, GetControlValue( theControl ) + 10 );
- break;
- case kControlPageUpPart:
- SetControlValue( theControl, GetControlValue( theControl ) - 100 );
- break;
- case kControlPageDownPart:
- SetControlValue( theControl, GetControlValue( theControl ) + 100 );
- break;
- }
-
- newVal = GetControlValue( theControl );
- TEPinScroll(0, theThis->lastScrollValue - newVal, theThis->aboutTEH);
- theThis->lastScrollValue = newVal;
- }